import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["customizeUnitCode"],
    _excluded2 = ["customizeUnitCode"],
    _excluded3 = ["customizeUnitCode"];

/**
 * NewOrganization 新版组织架构
 * @date: 2019-12-13
 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
/**
 * 更新平级部门
 * @param {Object} params - 参数
 */

export function updateDepartmentInformation(_x) {
  return _updateDepartmentInformation.apply(this, arguments);
}
/**
 * 禁用部门
 * @param {Object} params - 参数
 */

function _updateDepartmentInformation() {
  _updateDepartmentInformation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
    var customizeUnitCode, other;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            customizeUnitCode = _ref.customizeUnitCode, other = _objectWithoutProperties(_ref, _excluded);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/units"), {
              method: 'PUT',
              body: other,
              query: {
                customizeUnitCode: customizeUnitCode
              }
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _updateDepartmentInformation.apply(this, arguments);
}

export function disableDepartment(_x2) {
  return _disableDepartment.apply(this, arguments);
}
/**
 * 启用部门
 * @param {Object} params - 参数
 */

function _disableDepartment() {
  _disableDepartment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var tenantId, unitId, objectVersionNumber, _token;

    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            tenantId = params.tenantId, unitId = params.unitId, objectVersionNumber = params.objectVersionNumber, _token = params._token;
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/units/disable"), {
              method: 'POST',
              body: {
                tenantId: tenantId,
                unitId: unitId,
                objectVersionNumber: objectVersionNumber,
                _token: _token
              }
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _disableDepartment.apply(this, arguments);
}

export function enableDepartment(_x3) {
  return _enableDepartment.apply(this, arguments);
}
/**
 * 更新平级部门
 * @param {Object} params - 参数
 */

function _enableDepartment() {
  _enableDepartment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var tenantId, unitId, objectVersionNumber, _token;

    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            tenantId = params.tenantId, unitId = params.unitId, objectVersionNumber = params.objectVersionNumber, _token = params._token;
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/units/enable"), {
              method: 'POST',
              body: {
                tenantId: tenantId,
                unitId: unitId,
                objectVersionNumber: objectVersionNumber,
                _token: _token
              }
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _enableDepartment.apply(this, arguments);
}

export function updatePositionInformation(_x4) {
  return _updatePositionInformation.apply(this, arguments);
}
/**
 * 禁用岗位
 * @param {Object} params - 参数
 */

function _updatePositionInformation() {
  _updatePositionInformation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var unitCompanyId, unitId, positionId, customizeUnitCode;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            unitCompanyId = params.unitCompanyId, unitId = params.unitId, positionId = params.positionId, customizeUnitCode = params.customizeUnitCode;
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/companies/").concat(unitCompanyId, "/units/").concat(unitId, "/positions/").concat(positionId), {
              method: 'PUT',
              body: params,
              query: {
                customizeUnitCode: customizeUnitCode
              }
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updatePositionInformation.apply(this, arguments);
}

export function disablePosition(_x5) {
  return _disablePosition.apply(this, arguments);
}
/**
 * 启用岗位
 * @param {Object} params - 参数
 */

function _disablePosition() {
  _disablePosition = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var unitCompanyId, unitId, positionId;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            unitCompanyId = params.unitCompanyId, unitId = params.unitId, positionId = params.positionId;
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/companies/").concat(unitCompanyId, "/units/").concat(unitId, "/positions/disable/").concat(positionId), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _disablePosition.apply(this, arguments);
}

export function enablePosition(_x6) {
  return _enablePosition.apply(this, arguments);
}
/**
 * 新增员工详情
 * @param {Object} params - 参数
 */

function _enablePosition() {
  _enablePosition = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    var unitCompanyId, unitId, positionId;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            unitCompanyId = params.unitCompanyId, unitId = params.unitId, positionId = params.positionId;
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/companies/").concat(unitCompanyId, "/units/").concat(unitId, "/positions/enable/").concat(positionId), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _enablePosition.apply(this, arguments);
}

export function addEmployeeDetail(_x7) {
  return _addEmployeeDetail.apply(this, arguments);
}
/**
 * 新增员工详情
 * @param {Object} params - 参数
 */

function _addEmployeeDetail() {
  _addEmployeeDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref2) {
    var customizeUnitCode, other;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            customizeUnitCode = _ref2.customizeUnitCode, other = _objectWithoutProperties(_ref2, _excluded2);
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/plus/employees"), {
              method: 'POST',
              body: other,
              query: {
                customizeUnitCode: customizeUnitCode
              }
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _addEmployeeDetail.apply(this, arguments);
}

export function updateEmployeeDetail(_x8) {
  return _updateEmployeeDetail.apply(this, arguments);
}
/**
 * 获取员工数据
 * @param {Object} params - 参数
 */

function _updateEmployeeDetail() {
  _updateEmployeeDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref3) {
    var customizeUnitCode, other;
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            customizeUnitCode = _ref3.customizeUnitCode, other = _objectWithoutProperties(_ref3, _excluded3);
            return _context8.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/plus/employees"), {
              method: 'PUT',
              body: other,
              query: {
                customizeUnitCode: customizeUnitCode
              }
            }));

          case 2:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _updateEmployeeDetail.apply(this, arguments);
}

export function fetchEmployeeDetail(_x9) {
  return _fetchEmployeeDetail.apply(this, arguments);
}

function _fetchEmployeeDetail() {
  _fetchEmployeeDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    var employeeId, customizeUnitCode;
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            employeeId = params.employeeId, customizeUnitCode = params.customizeUnitCode;
            return _context9.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/plus/employees/").concat(employeeId), {
              method: 'GET',
              query: {
                customizeUnitCode: customizeUnitCode
              }
            }));

          case 2:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _fetchEmployeeDetail.apply(this, arguments);
}